<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------

namespace app\dao\activity\score;


use app\dao\BaseDao;
use app\model\activity\score\StoreScoreTaskRecord;

/**
 * 订单状态
 * Class StoreOrderStatusDao
 * @package app\dao\order
 */
class StoreScoreTaskRecordDao extends BaseDao
{
    /**
     * 设置模型
     * @return string
     */
    protected function setModel(): string
    {
        return StoreScoreTaskRecord::class;
    }

    /**
     * @param int $task_id
     * @return array|\crmeb\basic\BaseModel|mixed|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getTaskRecord(int $task_id, int $uid){
        return $this->getModel()->where('task_id', $task_id)->where('uid', $uid)->find();
    }

    /**
     * @param int $uid
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getUserTaskRecordList(int $uid){
        return $this->getModel()->where('uid', $uid)->where('uid', $uid)->select()->toArray();
    }

    /**
     * @param int $uid
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getUserTasksFinishNumber(int $uid){
        return $this->getModel()->field('task_id,count(*) as finish_num')->where('uid', $uid)->group('task_id')->select()->toArray();
    }
}
